{template 'common/header'}
 
<ul class="nav nav-tabs">
	<li><a href="{php echo $this->createWebUrl('business', array('op'=>'display'));}">网点列表</a></li>
	<li {if empty($id)}class="active"{/if}><a href="{php echo $this->createWebUrl('business', array('op'=>'edit'));}">添加网点</a></li>
	{if !empty($id)}
	<li class="active"><a href="{php echo $this->createWebUrl('business', array('op'=>'edit', 'id'=>$id));}">编辑网点</a></li>
	{/if}
</ul>
 
<div class="main">
	<form action="" method="post" class="form-horizontal form" id="form">
		<div class="panel panel-default">
			<div class="panel-heading">网点设置</div>
			<div class="panel-body">
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">名称</label>
					<div class="col-xs-12 col-sm-8">
						<input type="text" name="business[title]" class="form-control" value="{$business['title']}" />
					</div>
				</div>
				
				<!-- <div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">分配粉丝openid</label>
					<div class="col-xs-12 col-sm-8">
						<input type="text" name="business[openid]" class="form-control" value="{$business['openid']}" />
						<span class="input-group-addon"><a href="/web/index.php?c=mc&a=fans&" target="_blank">openid：点击这里获取粉丝管理中的粉丝编号</a></span>
					</div>
				</div> -->
							
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">选择分类</label>
						<div class="col-sm-8 col-xs-12">
							{php echo tpl_form_field_category_2level('category', $parent, $children, $pcate, $ccate)}
						</div>
					</div>				
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">图片</label>
					<div class="col-xs-12 col-sm-8">
					{php $logo = iunserializer($business['logo'])}
				
						{php echo tpl_form_field_multi_image('logo', $logo);}
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">网点电话</label>
					<div class="col-xs-12 col-sm-8">
						<input type="text" name="business[phone]" class="form-control" value="{$business['phone']}" />						
					</div>
				</div>				
				<!-- <div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">微信号</label>
					<div class="col-xs-12 col-sm-8">
						<input type="text" name="business[weixin]" class="form-control" value="{$business['weixin']}" />						
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">二维码</label>
					<div class="col-xs-12 col-sm-8">
						{php echo tpl_form_field_image('business[ewm]', $business['ewm']);}
					</div>
				</div> -->
				<!-- <div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">网址</label>
					<div class="col-xs-12 col-sm-8">
						<input type="text" name="business[net]" class="form-control" value="{$business['net']}" />						
					</div>
				</div> -->
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">地址</label>
					<div class="col-xs-12 col-sm-8">
					<input type="text" name="business[address]" id="address" class="form-control" value="{$business['address']}" />	
					<span class="input-group-addon">地址可以不用填写，获取定位时候自动添加</span>					
					</div>
				</div>

				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">地图</label>
					<div class="col-xs-12 col-sm-2">
					<input type="text" name="business[lng]" class="form-control"  id="lng" value="{$business['lng']}" />
					</div>
					<div class="col-xs-12 col-sm-2">
					<input type="text" name="business[lat]" class="form-control"  id="lat" value="{$business['lat']}" />		
					</div>
					<div type="button" class="btn btn-default col-sm-4" data-toggle="modal" data-target="#myModal">
					  点击选择定位坐标
					</div>

					<!-- Modal -->
					<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
					  <div class="modal-dialog" role="document">
						<div class="modal-content">
						  <div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
							<h4 class="modal-title" id="myModalLabel">地图选择</h4>
						  </div>
						  <div class="modal-body">
						   <iframe id="iframe" width="100%" height="500" frameborder=0 
						src="http://apis.map.qq.com/tools/locpicker?search=1&type=1&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77&referer=myapp">
					</iframe> 
					 
					<script>
							//iframe页面调用方法
							$(function(){ 

								adaptHeight();//动态适配高度
							   
								window.onresize = function() { //横屏、QQ浏览器变全屏模式下的时候，需要重新计算高度              
									adaptHeight();                
								}

								window.addEventListener('message', function(event) {
									var loc = event.data;
									document.getElementById("lng").value=loc.latlng.lat;
									document.getElementById("lat").value=loc.latlng.lng;
									document.getElementById("address").value=loc.poiaddress;
									alert('已选择完毕，您可以点击右上角X关闭');
								}, false);

								function adaptHeight() {
									var winH = $(window).height(); 
									var bodyH = document.documentElement.clientHeight; 
									if (winH > bodyH) {
										window.parent.document.getElementById("iframe").height=winH;
									} else {
										window.parent.document.getElementById("iframe").height=bodyH;
									}  
								}
							});
						</script>
						  </div>						 
						</div>
					  </div>
					</div>									
											
					</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">简介</label>
					<div class="col-xs-12 col-sm-8">
						<textarea  name="business[zy]" class="form-control">{$business['zy']}</textarea>						
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">描述</label>
					<div class="col-xs-12 col-sm-8">
						<textarea  name="business[desc]" class="form-control">{$business['desc']}</textarea>						
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">状态</label>
					<div class="col-xs-12 col-sm-8">
						<label class="radio radio-inline">
							<input type="radio" name="business[status]" value="1" {if intval($business['status']) != 2}checked="checked"{/if}> 已通过
						</label>
						<label class="radio radio-inline">
							<input type="radio" name="business[status]" value="2" {if intval($business['status']) == 2}checked="checked"{/if}> 待审核
						</label>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">是否推荐到首页</label>
					<div class="col-xs-12 col-sm-8">
						<label class="radio radio-inline">
							<input type="radio" name="business[recommended]" value="1" {if intval($business['recommended']) == 1}checked="checked"{/if}> 推荐
						</label>
						<label class="radio radio-inline">
							<input type="radio" name="business[recommended]" value="0" {if intval($business['recommended']) == 0}checked="checked"{/if}> 取消推荐
						</label>
					</div>
				</div>
				
				{if !empty($id)}
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">添加日期</label>
					<div class="col-xs-12 col-sm-8">
						<p class="form-control-static">{php echo date('Y-m-d', $business['time']);}</p>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">到期日期</label>
					<div class="col-xs-12 col-sm-8">
						{php $date = date('Y-m-d', $business['time'])}		
						{php echo tpl_form_field_date('daotime',date("Y-m-d",strtotime("$date +1 year")));}
					</div>
				</div>
				{/if}
				<div class="form-group">
					<div class="col-xs-12 col-sm-9 col-md-10 col-lg-10 col-sm-offset-3 col-md-offset-2 col-lg-offset-2">
						<input type="hidden" name="id" value="{$business['id']}" />
						<input name="submit" type="submit" value="提交" class="btn btn-primary" />
						<input type="hidden" name="token" value="{$_W['token']}" />
					</div>
				</div>
			</div>
		</div>
	</form>
</div>
 
<script>
require(['jquery', 'util'], function($, util){
	$(function(){
		$('#form').submit(function(){
			if($('input[name="business[name]"]').val() == ''){
				util.message('请填写商品名称.');
				return false;
			}			
			if($('input[name="business[logo]"]').val() == ''){
				util.message('请上传商家外观照片.');
				return false;
			}
			if($('input[name="business[phone]"]').val() == ''){
				util.message('请上传商家电话.');
				return false;
			}						
			return true;
		});
	});
});
</script>

{template 'common/footer'}